package com.linktco.common.utils;

import java.lang.reflect.Field;

public class RemoveSpacesProcessor {
    public static void process(Object obj) {
        Class<?> clazz = obj.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (field.getType() != String.class) {
                continue;
            }

            if (field.isAnnotationPresent(RemoveSpaces.class)) {
                try {
                    field.setAccessible(true);
                    String value = (String) field.get(obj);
                    if (value != null) {
                        value = value.replaceAll(" ", "");
                        field.set(obj, value);
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
